home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 2002 Tom Parker (tom@carrott.org),
- Matthias Münch (matthias@amigaworld.de)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- In addition, as a special exception, Tom Parker and Matthias Münch give
- permission to link the code of this program with a TCP stack of your
- choice, any official MUI libraries or classes and any custom MUI classes
- that should be necessary for the operation of this program. This
- exception also gives you permission to distribute linked combinations
- including this software with any of the before-mentioned libraries and
- classes. You must obey the GNU General Public License in all respects for
- all of the code used other than that provided by the before-mentioned
- libraries and classes. As part of this exception you are obliged to
- follow the license terms of the before-mentioned libraries, this license
- does not compel you to follow those terms, but if you do not then you may
- not link with those libraries. If you modify this file, you may extend
- this exception to your version of the file, but you are not obligated to
- do so. If you do not wish to do so, delete this exception statement from
- your version.
- */
- /*
- ** user information window
- */
-
- #include "common.h"
-
- #include <MUI/NListview_mcc.h>
- #include <MUI/NFloattext_mcc.h>
-
- static ULONG userinfo_new(struct IClass *cl, Object *obj, struct opSet *msg);
- static void userinfo_showver(struct userinfodata *data, ikspak *pak);
-
-
- MUI_DISPATCH(userinfo_dispatch)
- {
- switch(msg->MethodID)
- {
- case OM_NEW:
- return userinfo_new(cl,obj,(APTR)msg);
-
- case USERINFO_UPDATE:
- {
- struct userinfodata *data = INST_DATA(cl,obj);
- int parts;
- char *tmp;
- iks *x, *y;
- tmp = mui_sget(data->namestr);
- x = iks_make_iq(IKS_TYPE_SET, IKS_NS_ROSTER);
- y = iks_insert(iks_child(x), "item");
-
- // When doing an update we want to refer to the user without their
- // resource specification - a user only has one name, not a name for
- // each resource.
- //
- // However agents must be referred to using their full JID, including
- // resource or strange things happen to your roster.
- if (data->u->id->user == NULL) {
- parts = IKS_ID_USER | IKS_ID_SERVER | IKS_ID_RESOURCE;
- } else {
- parts = IKS_ID_USER | IKS_ID_SERVER;
- }
-
- iks_insert_attrib(y, "jid", iks_id_printx(data->u->id, parts));
- if(tmp) iks_insert_attrib(y, "name", convert_utf8(tmp));
- iks_send(net.parser, x);
- iks_delete(x);
- return 0;
- }
-
- case USERINFO_ASKVER:
- {
- struct userinfodata *data = INST_DATA(cl,obj);
- ikspak *pak = (ikspak *)MARG1;
-
- if(pak)
- {
- userinfo_showver(data, pak);
- }
- else
- {
- iks *x;
- x = iks_make_iq(IKS_TYPE_GET, IKS_NS_VERSION);
- iks_insert_attrib(x, "to", iks_id_print(data->u->id));
- iks_send(net.parser, x);
- iks_delete(x);
- }
- return 0;
- }
-
- case USERINFO_CLOSE:
- ((struct userinfodata *)INST_DATA(cl,obj))->u->infowin = NULL;
- DoMethod(gui.app, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
- return 0;
- }
- return DoSuperMethodA(cl,obj,msg);
- }
-
-
- static ULONG userinfo_new(struct IClass *cl, Object *obj, struct opSet *msg)
- {
- static const char *pages[] =
- {
- "Presence",
- "Client",
- NULL
- };
- static const char *subsents[] =
- {
- "None",
- "To",
- "From",
- "Both",
- NULL
- };
- struct userinfodata *data;
- Object *namestr, *idtxt, *grouptxt, *subs, *subscyc, *stat, *note, *upbut, *canbut;
- Object *clientstr, *verstr, *osstr, *verbut;
- juser u;
- char *tmp;
-
- obj = (Object *)DoSuperNew(cl,obj,
- MUIA_Window_ID, MAKE_ID('U','I','N','F'),
- MUIA_Window_Title, MSG_USERINFO_TITLE,
- MUIA_HelpNode, "window-info",
- WindowContents, VGroup,
- Child, ColGroup(2),
- Child, Label2(MSG_USERINFO_NAME),
- Child, (ULONG) namestr = StringObject,
- StringFrame,
- MUIA_CycleChain, 1,
- End,
- Child, Label2(MSG_USERINFO_JID),
- Child, (ULONG) idtxt = TextObject,
- TextFrame,
- MUIA_Background, MUII_TextBack,
- End,
- Child, Label2(MSG_USERINFO_GROUP),
- Child, (ULONG) grouptxt = TextObject,
- TextFrame,
- MUIA_Background, MUII_TextBack,
- End,
- End,
- Child, RegisterGroup(pages),
- Child, ColGroup(2),
- Child, Label1(MSG_USERINFO_SUBS),
- Child, HGroup,
- Child, (ULONG) subs = TextObject,
- TextFrame,
- MUIA_Background, MUII_TextBack,
- End,
- Child, Label1(MSG_USERINFO_CHANGETO),
- Child, (ULONG) subscyc = CycleObject,
- MUIA_HorizWeight, 0,
- MUIA_CycleChain, 1,
- MUIA_Cycle_Entries, subsents,
- End,
- End,
- Child, Label1(MSG_USERINFO_STATUS),
- Child, (ULONG) stat = TextObject,
- TextFrame,
- MUIA_Background, MUII_TextBack,
- End,
- Child, VGroup,
- MUIA_HorizWeight, 0,
- Child, Label1(MSG_USERINFO_NOTE),
- Child, RectangleObject, End,
- End,
- Child, NListviewObject,
- MUIA_FixHeightTxt, "\n\n\n",
- MUIA_NListview_NList, (ULONG) note = NFloattextObject,
- ReadListFrame,
- End,
- End,
- End,
- Child, VGroup,
- Child, ColGroup(2),
- Child, Label1(MSG_USERINFO_CLIENT),
- Child, (ULONG) clientstr = TextObject,
- TextFrame,
- MUIA_Background, MUII_TextBack,
- End,
- Child, Label1(MSG_USERINFO_VERSION),
- Child, (ULONG) verstr = TextObject,
- TextFrame,
- MUIA_Background, MUII_TextBack,
- End,
- Child, Label1(MSG_USERINFO_OS),
- Child, (ULONG) osstr = TextObject,
- TextFrame,
- MUIA_Background, MUII_TextBack,
- End,
- End,
- Child, HGroup,
- Child, HSpace(0),
- Child, verbut = mui_button(MSG_USERINFO_ASKVER_GAD),
- End,
- End,
- End,
- Child, RectangleObject,
- MUIA_FixHeightTxt, "M",
- MUIA_Rectangle_HBar, TRUE,
- End,
- Child, HGroup,
- Child, upbut = mui_button(MSG_USERINFO_UPDATE_GAD),
- Child, canbut = mui_button(MSG_USERINFO_CLOSE_GAD),
- End,
- End,
- TAG_MORE, msg->ops_AttrList);
-
- if(!obj) return(0);
-
- u = (juser)GetTagData(USERINFO_OF, NULL, msg->ops_AttrList);
- set(namestr, MUIA_String_Contents, (ULONG) convert_locale(u->name));
- set(idtxt, MUIA_Text_Contents, (ULONG) iks_id_print(u->id));
- set(grouptxt, MUIA_Text_Contents, (ULONG) convert_locale(u->group));
- set(note, MUIA_Floattext_Text, (ULONG) convert_locale(u->status));
-
- tmp = "None.";
- switch(u->subs)
- {
- case JUSER_TO: tmp=MSG_USERINFO_SUBSCRIPTION_TO; break;
- case JUSER_FROM: tmp=MSG_USERINFO_SUBSCRIPTION_FROM; break;
- case JUSER_BOTH: tmp=MSG_USERINFO_SUBSCRIPTION_BOTH; break;
- }
- set(subs, MUIA_Text_Contents, (ULONG) tmp);
-
- tmp = "Available.";
- switch(u->show)
- {
- case IKS_SHOW_UNAVAILABLE: tmp=MSG_USERINFO_STATUS_UNAVAILABLE; break;
- case IKS_SHOW_CHAT: tmp=MSG_USERINFO_STATUS_CHAT; break;
- case IKS_SHOW_AWAY: tmp=MSG_USERINFO_STATUS_TEMP_AWAY; break;
- case IKS_SHOW_XA: tmp=MSG_USERINFO_STATUS_EXTENDED_AWAY; break;
- case IKS_SHOW_DND: tmp=MSG_USERINFO_STATUS_DND; break;
- }
- set(stat, MUIA_Text_Contents, (ULONG) tmp);
-
- data = INST_DATA(cl,obj);
- data->u = u;
- data->namestr = namestr;
- data->clientstr = clientstr;
- data->verstr = verstr;
- data->osstr = osstr;
-
- userinfo_showver(data, NULL);
-
- DoMethod(upbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, USERINFO_UPDATE);
- DoMethod(verbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 2, USERINFO_ASKVER, 0);
-
- DoMethod(canbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, USERINFO_CLOSE);
- DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, obj, 1, USERINFO_CLOSE);
-
- return((ULONG)obj);
- }
-
-
- static void userinfo_showver(struct userinfodata *data, ikspak *pak)
- {
- iks *x;
-
- if(pak)
- {
- if(data->u->verpak) iks_delete(data->u->verpak->x);
- data->u->verpak = pak;
- }
- else
- {
- pak = data->u->verpak;
- if(!pak) return;
- }
-
- x = iks_find(pak->x, "query");
- set(data->clientstr, MUIA_Text_Contents, (ULONG) iks_find_cdata(x, "name"));
- set(data->verstr, MUIA_Text_Contents, (ULONG) iks_find_cdata(x, "version"));
- set(data->osstr, MUIA_Text_Contents, (ULONG) iks_find_cdata(x, "os"));
- }
-
-
- void userinfo_of(juser u)
- {
- Object *win;
-
- if(u->infowin) {
- DoMethod(u->infowin, MUIM_Window_ToFront);
- return;
- }
-
- win = NewObject(gui.userinfo_mcc->mcc_Class, NULL, USERINFO_OF, (ULONG) u, TAG_DONE);
- if(win) {
- DoMethod(gui.app, OM_ADDMEMBER, win);
- set(win, MUIA_Window_Open, TRUE);
- u->infowin = win;
- }
- }
-
-
- void userinfo_update(ikspak *pak)
- {
- juser u;
-
- u = roster_find(pak->from);
- if(!u) return;
-
- if(u->infowin)
- DoMethod(u->infowin, USERINFO_ASKVER, pak);
- else
- u->verpak = pak;
- }
-